Garbage collection method for data storage device

ABSTRACT

A garbage collection method for a data storage device includes steps of: entering a background mode from a foreground mode; selecting a plurality of source data blocks from a plurality of in-use data blocks; dividing a mapping table into a plurality of sub-mapping tables and selecting one of the sub-mapping tables as a target sub-mapping table, wherein the target sub-mapping table is used to manage one of the source data blocks; selecting a destination data block from a plurality of spare data blocks; and sequentially updating a correspondence relationship of data stored in the target sub-mapping table from the source data blocks to the destination data block, wherein the updating comprises copying the data stored in the source data blocks to the destination data block.

FIELD OF THE INVENTION

The present invention relates to a technique for data storage, and moreparticularly to a garbage collection method for a data storage device.

BACKGROUND OF THE INVENTION

A data storage device, in particular a data storage device using anon-volatile storage medium, includes a plurality of data blocks. Eachdata block includes a plurality of data pages, each data page is forstoring data with at least one storage unit, and the storage unit may be512 B (byte) or preferably 4 KB. Data blocks are also divided into emptydata blocks (or spare data blocks) and non-empty data blocks (or in-usedata blocks) depending on whether data is stored therein or not. Fordata management and access, the data storage device needs to establishand store a host-to-flash physical address (H2F) mapping table, which issimply referred to as a mapping table in the present invention. When thedata storage device is in operation, the mapping table is copied to adynamic random access memory (DRAM) to increase the efficiency of datamanagement and access. In addition, depending on the size of recordedcontent, in general the size of the mapping table is 1/1000 of the datastorage capacity of the data storage device. For example, if the size ofa data storage device is 256 GB, the size of the corresponding mappingtable is 256 MB. Therefore, to store an entire mapping table, the sizeof the DRAM is preferably greater than or equal to 256 MB.

For a data storage device that is not provided with a DRAM or onlyprovided with a small-sized DRAM (i.e., the DRAM is not large enough tostore an entire mapping table), there is a technical need for providinga solution as to how to use static random access memory (SRAM) orsmall-sized DRAM for data management and access.

SUMMARY OF THE INVENTION

One objective of the present invention is to provide a garbagecollection method for a data storage device. The garbage collectionmethod can reduce the number of times for swapping sub-mapping table,and thereby reducing the resources consumed by the data storage device.

The present invention provides a garbage collection method for a datastorage device, which includes steps of: entering a background mode froma foreground mode; selecting a plurality of source data blocks from aplurality of in-use data blocks; dividing a mapping table into aplurality of sub-mapping tables and selecting one of the sub-mappingtables as a target sub-mapping table, wherein the target sub-mappingtable is used to manage one of the source data blocks; selecting adestination data block from a plurality of spare data blocks; andsequentially updating a correspondence relationship of data stored inthe target sub-mapping table from the source data blocks to thedestination data block, wherein the updating comprises copying the datastored in the source data blocks to the destination data block.

In summary, in the present invention, because the garbage collectionprogram is performed on the data blocks in accordance with the completerecord content of a sub-mapping table, the present invention caneffectively reduce the number of times for swapping mapping table andreduce the resource consumed by the data storage device.

BRIEF DESCRIPTION OF THE DRAWINGS

Other advantages, objectives and features of the present invention willbecome apparent from the following description referring to the attacheddrawings.

FIG. 1 depicts a data storage device in accordance with an embodiment ofthe present invention and its electrical coupling relationship with ahost;

FIG. 2 is a flowchart of a garbage collection method in accordance withan embodiment of the present invention;

FIG. 3 is a schematic diagram of a flash physical-to-host logicaladdress mapping table for data blocks 302-308;

FIG. 4 is a schematic diagram for illustrating copying of valid datafrom data blocks 302-308 to data block 310;

FIG. 5 is a schematic diagram for illustrating recording ofcorrespondence of data to be copied to the target sub-mapping table 322and forming a target sub-mapping table 322′;

FIG. 6 is a schematic diagram for illustrating sequential copying ofdata having logical block addressing values (LBAs) of 0-15 from datablock 308 to data block 312; and

FIG. 7 is a schematic diagram for illustrating recording ofcorrespondence of data to be copied to the target sub-mapping table 322′and forming a target sub-mapping table 322″.

DETAILED DESCRIPTION OF PREFERRED EMBODIMENTS

The present invention will now be described more specifically withreference to the following embodiments. It is to be noted that thefollowing descriptions of preferred embodiments of this invention arepresented herein for purpose of illustration and description only. It isnot intended to be exhaustive or to be limited to the precise formdisclosed.

FIG. 1 depicts a data storage device in accordance with an embodiment ofthe present invention and its electrical coupling relationship with ahost. Referring to FIG. 1, the host 100 mainly includes a centralprocessing unit 110 and a connection interface 120. The connectioninterface 120 is adapted to electrically couple the data storage device200 of the present embodiment. The central processing unit 110 isconfigured to transmit commands and data to the data storage device 200via the connection interface 120. For example, the central processingunit 110 transmits a read command to the data storage device 200, ortransmits a write command and data to be written into the data storagedevice 200 to the data storage device 200. In the present embodiment,the host 100 is implemented as a computer, a mobile phone, a tabletcomputer, a camera or other handheld electronic device having computingfunction.

The data storage device 200 mainly includes a control unit 210 and anon-volatile storage medium 220. The control unit 210 is electricallycoupled to the non-volatile storage medium 220 and configured to controlthe operation (e.g., data access or data erase) of the non-volatilestorage medium 220. In the present embodiment, the non-volatile storagemedium 220 is, for example, a flash memory, a magnetoresistive randomaccess memory (RANI), a ferroelectric RANI or a resistive RANI (RRANI)capable of long-term data storage. The non-volatile storage medium 220has a plurality of data blocks (e.g., data block 221), and each of thedata blocks has a plurality of data pages. In the present embodiment,each of the data blocks has ten data pages, which are data pages 1-9.The data storage device 200 may further include a small-sized DRAM thatis not large enough to store an entire mapping table, and the size of anentire mapping table is preferably greater than or equal to athousandths of the storage capacity of the non-volatile storage medium220.

The control unit 210 mainly includes an interface logic 212, amicroprocessor 214, a control logic 216 and a volatile storage medium218, wherein the volatile storage medium 218 is implemented, forexample, by static random access memory. The microprocessor 214 of thecontrol unit 210 is electrically coupled to the interface logic 212 andthe control logic 216. The control logic 216 is electrically coupled tothe non-volatile storage medium 220 and the volatile storage medium 218.The microprocessor 214 is configured to access data in the non-volatilestorage medium 220 and the volatile storage medium 218 via the controllogic 216. Further, the microprocessor 214 is configured to receivecommands or data from the host 100 via the interface logic 212, whereinthe aforementioned commands are, for example, a write command, a readcommand or a flush command.

In the following description, a garbage collection method of the datastorage device in accordance with an embodiment of the present inventionwill be described by an example in which the data storage device 200 isnot provided with a small-sized DRAM. However, the garbage collectionmethod of the data storage device of the present invention may alsoapply to the data storage device 200 provided with a small-sized DRAM,and the present invention is not limited thereto.

FIG. 2 is a flowchart of a garbage collection method in accordance withan embodiment of the present invention. Referring to FIGS. 1 and 2. Asshown, first, step S202: entering a background mode from a foregroundmode. Specifically, the data storage device 200 would enter thebackground mode from the foreground mode when the host 100 stops sendingcommands or data, or the number of spare data blocks in the non-volatilestorage medium 220 is lower than a threshold, or the power state isswitched into a power saving state or other specific state. Thenon-volatile storage medium 220 includes a plurality of data blocks, forexample, 65,536 data blocks, which are data blocks #0 to #65535. Thedata blocks #0 to #59999 are in-use data blocks, and the data block#60000 to #65535 are spare data blocks.

Thereafter, step S204: selecting a plurality of source data blocks fromthe in-use data blocks. Specifically, one of the source data blocks isone of the in-use data blocks having the least valid data count; or oneof the source data blocks is one of the in-use data blocks having themost or least erase count; or one of the source data blocks is one ofthe in-use data blocks having the most or least read count; or thesource data blocks are randomly selected from the in-use data blocks; orthe source data blocks are sequentially selected from the in-use datablocks according to a serial number. As shown in FIG. 3, the controlunit 210 selects a plurality of in-use data blocks, for example, datablocks 302-308 (i.e., data bocks #1, #20, #300 and #4000) out of the60,000 in-use data blocks (i.e., data blocks #0 to #59999) as the sourcedata blocks. The four source data blocks (i.e., data bocks #1, #20, #300and #4000) are preferably the first four of the 60,000 in-use datablocks (i.e., data blocks #0 to #59999) having the least valid datacount; or the four source data blocks are preferably the first four ofthe 60,000 in-use data blocks having the least erase count; or the foursource data blocks are randomly selected from the 60,000 in-use datablocks; or the four source data blocks are preferably the first four ofthe 60,000 in-use data blocks having the first four data block numbers(i.e., data bocks #0 to #3) or having the last four data block numbers(i.e., data bocks #59996 to #59999). In addition, the flashphysical-to-host logical address (F2H) mapping table of the data blocks302 to 308 in FIG. 3 is a schematic diagram for explaining thefollowings, and the present invention is not limited thereto.

Thereafter, step S206: dividing the mapping table into a plurality ofsub-mapping tables and selecting one of the sub-mapping tables as atarget sub-mapping table. Specifically, the target sub-mapping table isused to manage one of the source data blocks; or the target sub-mappingtable is sequentially selected from the sub-mapping tables; or thetarget sub-mapping table is randomly selected from the sub-mappingtables. In addition, the size of the target sub-mapping table ispreferably larger than or equal to the size of the source data block. Inaddition, preferably, the content of the mapping table is sequentiallyestablished in accordance with the index of the logical block addressing(LBA) or established in accordance with the receiving order of the LBA.Assuming that the size of the mapping table is 256 MB and the storagecapacity of the volatile storage medium 218 is only 64 KB or if only 64KB of capacity is reserved for storing a sub-mapping table, the controlunit 210 divides the mapping table into 4,000 sub-mapping tables, whichare sub-mapping tables #0 to #3999, so that the size of the sub-mappingtable is consistent with the storage capacity of the volatile storagemedium 218. Assuming that the target sub-mapping table is sequentiallyselected from the sub-mapping tables, the sub-mapping table being thefirst to be selected would be sub-mapping table #0 or sub-mapping table#3999. Assuming that the target sub-mapping table is randomly selectedfrom the sub-mapping tables, the sub-mapping table being the first to beselected may be sub-mapping table #1000. Assuming that the content ofthe mapping table is sequentially established in accordance with theindex LBA, the sub-mapping tables 322, 324 and 326 correspond to thesub-mapping tables #0, #1 and #625, respectively. In the correspondencerelationship of the flash physical-to-host logical address of the datastored in the data blocks 302 to 308 (in short, a correspondencerelationship), the label x indicates invalid data and the label FFindicates that no record of correspondence relationship of the data.Since the LBA of the first record of valid data in the data block 302 is0 and LBA 0 is corresponded to the first record of the sub-mapping table#0 via the calculation of address, the sub-mapping table 322 would bethe first to be selected as the target sub-mapping table. In addition,the calculation of address is prior art, no redundant detail is to begiven herein.

Thereafter, step S208: selecting a destination data block from aplurality of spare data blocks. Specifically, the destination data blockis randomly selected from the spare data blocks; or the destination datablock is sequentially selected from the spare data blocks; or thedestination data block is preferably the spare data blocks having themost erase count. Assume that the control unit 210 selects one sparedata block, such as data block #60000, as the destination data block 310from the data blocks #60000 to #65535. If the selection is based on asequential manner, the data block #60000 or the data area block #65535is selected as the destination data block 310. If the selection is tochoose the one having the most erase count, the data block #65432 may beselected as the destination data block 310. In the followingdescription, data block #60000 is selected as the data block 310 forillustration, but the present invention is not limited thereto.

Thereafter, step S210: sequentially updating the correspondencerelationship of the data stored in the target sub-mapping table from thesource data blocks to the destination data block, wherein the updatingincludes copying the data stored in the source data blocks to thedestination data block. Referring to FIGS. 3-7. As shown in FIG. 3, thetarget sub-mapping table 322 records the correspondence relationship ofthe data having LBAs of 0-15, and these records of data are stored indata blocks 302-308, respectively. As shown in FIG. 4, the valid data(with the label S) of LBAs 0-15 is sequentially copied from the datablocks 302-308 to the data block 310, and the correspondencerelationship of the copied data is recorded to the target sub-mappingtable 322, which then becomes the target sub-mapping table 322′, asshown in FIG. 5. Since the correspondence relationship of invalid orvalid data stored in the data block 304 has been updated, the data block304 does not contain any valid data and therefore can be recovered as aspare data block, thereby achieving the purpose of garbage collection.Conventionally, it would take a long time to swap a sub-mapping table ina data storage device provided with a small-sized DRAM. On the contrary,since the garbage collection method of the present invention performssub-mapping table swapping after updating the content of the (target)sub-mapping table, not only the purpose of garbage collection isachieved, but also the time for performing garbage collection is reducedas swapping frequency of the mapping table is reduced.

Thereafter, step S212: determining whether the correspondencerelationship of the data stored in the target sub-mapping table isupdated. If yes, the garbage collecting method of the present inventionis ended. If no, step S208 is performed again. In the above example,since the size of the data block 310 is limited, the correspondencetable of the data in the target sub-mapping table 322 is only partiallyupdated. Therefore, if the determination at step S212 is no and when thestep S208 is re-performed, another data block (e.g., data block #60001)becomes the destination data block as shown in the data block 312. Asshown in FIG. 6, the data (with the label Y) having LBAs of 0-15 issequentially copied from the data block 308 to the data block 312 andthe correspondence relationship of the copied data is recorded to thetarget sub-mapping table 322′, which then becomes the target sub-mappingtable 322″, as shown in FIG. 7. At this time, the correspondencerelationship of the data stored in the target sub-mapping table 322 hasbeen completely updated (that is, the target sub-mapping table 322 hasbeen updated to the target sub-mapping table 322″), and the garbagecollection method of the present invention is ended.

When the garbage collection method of the present invention is performedagain, since the LBA of the first record of valid data in the data block302 is 23 and LBA 23 is corresponded to the eighth record of thesub-mapping table #1 via the calculation of address, the sub-mappingtable 324 would be the first to be selected as the target sub-mappingtable. When the sub-mapping table 324 is updated, the data blocks 302and 306 may also be recovered as spare data blocks.

It is to be noted that the order of steps S202 to S208 is not so limitedas the above; for example, step S206 for selecting the targetsub-mapping table may be performed first, and then step S204 forselecting a plurality of source data block and step S208 for selecting adestination data block are performed sequentially; the user can adjustthe order of steps according to the actual requirements.

In summary, in the present invention, because the garbage collectionprogram is performed on the data blocks in accordance with the completerecord content of a sub-mapping table, the present invention caneffectively reduce the number of times for swapping mapping table duringthe garbage collection process and reduce the resource and time consumedby the data storage device, thereby achieving the objective of thepresent invention.

While the invention has been described in terms of what is presentlyconsidered to be the most practical and preferred embodiments, it is tobe understood that the invention needs not be limited to the disclosedembodiments. On the contrary, it is intended to cover variousmodifications and similar arrangements included within the spirit andscope of the appended claims which are to be accorded with the broadestinterpretation so as to encompass all such modifications and similarstructures.

What is claimed is:
 1. A garbage collection method for a data storagedevice, comprising: entering a background mode from a foreground mode;selecting a plurality of source data blocks from a plurality of in-usedata blocks; dividing a mapping table into a plurality of sub-mappingtables and selecting one of the sub-mapping tables as a targetsub-mapping table, wherein the target sub-mapping table is used tomanage one of the source data blocks; selecting a destination data blockfrom a plurality of spare data blocks; and sequentially updating acorrespondence relationship of data stored in the target sub-mappingtable from the source data blocks to the destination data block, whereinthe updating comprises copying the data stored in the source data blocksto the destination data block.
 2. The garbage collection methodaccording to claim 1, further comprising: determining whether thecorrespondence relationship of the data stored in the target sub-mappingtable has been completely updated; and if no, selecting anotherdestination data block from the spare data blocks.
 3. The garbagecollection method according to claim 1, wherein one of the source datablocks is one of the in-use data blocks having an extreme value of validdata count.
 4. The garbage collection method according to claim 1,wherein one of the source data blocks is one of the in-use data blockshaving an extreme value of erase count.
 5. The garbage collection methodaccording to claim 1, wherein one of the source data blocks is one ofthe in-use data blocks having an extreme value of read count.
 6. Thegarbage collection method according to claim 1, wherein the source datablocks are randomly selected from the in-use data blocks.
 7. The garbagecollection method according to claim 1, wherein the source data blocksare sequentially selected from the in-use data blocks according to aserial number.
 8. The garbage collection method according to claim 1,wherein the target sub-mapping table is sequentially selected from thesub-mapping tables.
 9. The garbage collection method according to claim1, wherein the target sub-mapping table is randomly selected from thesub-mapping tables.
 10. The garbage collection method according to claim1, wherein the destination data block is randomly selected from thespare data blocks.
 11. The garbage collection method according to claim1, wherein the destination data block is sequentially selected from thespare data blocks.
 12. The garbage collection method according to claim1, wherein the destination data block is one of the spare data blockshaving an extreme value of erase count.
 13. The garbage collectionmethod according to claim 1, wherein the data storage device comprisesthe in-use data blocks storing valid data and the spare data blocks notstoring the valid data.
 14. The garbage collection method according toclaim 1, wherein the data storage device comprises a dynamic randomaccess memory (DRAM), and a size of the mapping table is larger than asize of the DRAM.
 15. The garbage collection method according to claim1, wherein the background mode is entered from the foreground mode whenthe data storage device does not receive a command.
 16. The garbagecollection method according to claim 1, wherein the background mode isentered from the foreground mode when a total number of the spare datablocks is lower than a threshold.
 17. The garbage collection methodaccording to claim 1, wherein the background mode is entered from theforeground mode when a power state of the data storage device ischanged.